import { ReducersMapObject, Reducer, AnyAction } from 'redux';
import { connectRouter } from "connected-react-router";
import history from '../history';
import home from './home';
import mine from './mine';
import profile from './profile';
import cart from "./cart";
import { combineReducers } from "redux-immer";
import produce from "immer";

let reducers: ReducersMapObject = {
  router: connectRouter(history),
  home,
  mine,
  profile,
  cart
}

// 这是得到一个类型.key 是reducers对象的key, 值是reducers对象值的返回值 的类型,就是各个分状态
type CombinedState = {
  [key in keyof typeof reducers]: ReturnType<typeof reducers[key]>
}


let reducer: Reducer<CombinedState> = combineReducers<CombinedState>(
  produce,
  reducers
);

export { CombinedState };
export default reducer;
